#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <ctime>
#include <iomanip>


#include "GameTree.h"
#include "common_func.h"


using namespace std;
void initZobrist();


char MoveTab[32][5];
char OrderTab[34][34];

int main()
{   initZobrist();
    char chess_table[32];
    char chess_state[32];

    char depth = 1;
    
    init_MoveTab(MoveTab);
    init_OrderTab(OrderTab);
    
    move rootMove(32,32);
    
    init_chess_table(chess_table, chess_state);
    
    print_table(chess_table);
    
    man_assign(chess_table, chess_state);
    
    GameTree* T = new GameTree(chess_table, chess_state, 1, 0);
    
    print_table(T->_root->_board);
    int d;
    cout << "How deep do you want? ";
    cin >> d;
    cout << endl;
    char deep = (char)d;
    T->_height = deep + 1;
    T->_root->_depth = deep;
    T -> _root -> _stop = 0;
    GameTreeNode* kid = NULL;
    int val = T->AlphaBeta(T->_root, deep, -61000, 63000, kid);
    
    cout << "depth : " << (int)T->_root->_depth << endl;
    cout << "I have " << T->_root->_child.size() << " children" << endl;
    
    if(kid==NULL)
        cout<<"Sorry No news"<<endl;
    else{
    cout<<"The best choice is from "<<(int)kid->_path._from<<" to "<<(int)kid->_path._to<<endl;
    }
    cout<<"the root's value is : "<<T->_root->utility()<<endl;
    //cout<<"the score for next is "<<kid->utility() -  T->_root->utility()<<endl;
    cout<<"hh:"<<val<<endl;

    
    T->printTreeJS();
    //for(int i=0;i<640;i++)
    //cout<< Hash_Table[i]->key<<" fuck  "<<Hash_Table[i]->depth<<" fuck2 "<<endl;

    system("pause");
    
    return 0;
}
